<script setup lang="ts">
import { useRouter } from 'vue-router'
const props = defineProps<{
  title?: string
  rightText?: string
  back?: () => void
}>()
const emits = defineEmits<{
  (e: 'rightClick'): void
  (e: 'leftClick'): void
}>()
const router = useRouter()
const onClickLeft = () => {
  // TODO 点击左侧返回按钮
  // emits('leftClick')
  // 需求：如果有上一页，返回上一页，没有返回首页
  // if(组件标签上有相应的返回事件处理){return}
  if (props.back) {
    return props.back()
  }
  if (history.state.back) {
    router.back()
  } else {
    router.push('/')
  }
}
const onClickRight = () => {
  // TODO 点击右侧文字按钮
  emits('rightClick')
}
</script>

<template>
  <van-nav-bar
    fixed
    left-arrow
    :title="title"
    :right-text="rightText"
    @click-left="onClickLeft"
    @click-right="onClickRight"
  ></van-nav-bar>
</template>

<style lang="scss" scoped>
// vue2 ::v-deep   vue3  :deep(){}
:deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
    }
  }
}
</style>
